package org.call.hi.url;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.client.RestTemplate;

import com.netflix.discovery.DiscoveryClient;


@Service
public class   HelloService {

	@Autowired
    RestTemplate restTemplate;
	
	@Autowired
    LoadBalancerClient loadBalancerClient;
	
	public String hiService(String name)
    {
		return restTemplate.getForObject("http://localhost:8762/hello?name="+name,String.class);
    }
	
	
	
	public String hiService2(String name)
    {
		ServiceInstance serviceInstance = loadBalancerClient.choose("SERVICE-HI");
        String url = "http://" + serviceInstance.getHost() + ":" + serviceInstance.getPort();
        System.out.println("tmp url["+ url+"]");
        url=url+"/hello?name="+name;
        System.out.println("tmp url2["+ url+"]");
		return restTemplate.getForObject(url,String.class);
    }
	
	@Autowired
	DiscoveryClient client;
	
	
	
}


